/**
//给定一个二叉树，返回它的 后序 遍历。 
//
// 示例: 
//
// 输入: [1,null,2,3]  
//   1
//    \
//     2
//    /
//   3 
//
//输出: [3,2,1] 
//
// 进阶: 递归算法很简单，你可以通过迭代算法完成吗？ 
// Related Topics 栈 树 深度优先搜索 二叉树 👍 699 👎 0

*/

package com.xixi.dataStructure.tree.binaryTree;

import com.xixi.dataStructure.tree.TreeNode;

import java.util.LinkedList;
import java.util.List;

public class ID00145BinaryTreePostorderTraversal {
public static void main(String[] args) {
Solution solution = new ID00145BinaryTreePostorderTraversal().new Solution();
}


//leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {

    List<Integer> resultList = new LinkedList<>();

    public List<Integer> postorderTraversal(TreeNode root) {

        if(root == null){
            return resultList;
        }

        postorderTraversal(root.left); //先左子树
        postorderTraversal(root.right); //后右子树
        resultList.add(root.val);//最后打印自己

        return resultList;
    }
}
//leetcode submit region end(Prohibit modification and deletion)




}